import { wxRequest } from '../../../utils/server.js';
const _wxRequest = new wxRequest();
const app = getApp()
Page({
  data: {
    imgUrl: app.globalData.imgUrl,
    uploadUrl: wx.getStorageSync('uploadUrl'),
    pageNo: 1,
    hasNextPage: false,
    list: [],
    keyword: '',
  },


  onShow: function () {
    this.getlist()
  },

  //查询列表
  getlist: function () {
    _wxRequest.wxTonkenAjax({
      url: app.globalData.apiUrl + '/odr/protected/settle/myList',
      method: 'POST', 
      data: {
        pageNo: this.data.pageNo
      }
    }, (res) => {

      let list = res.list;
      if (this.data.pageNo !== 1) {
        list = this.data.list.concat(list);
      }


      list.map(item=>{
        if (item.id>0 && item.monthName){
          var monthName=item.monthName 
           item.dateMoth = monthName.substring(5, 8)
           item.dateName = monthName.substring(9, 30)
          }

        if (item.payDate) {
          item.payDateText = item.payDate.substring(0, 11)
        }
      })
      
      console.log(list,'list')


      this.setData({
        list: list,
        pageNo: res.page.pageNo,
        hasNextPage: res.page.hasNextPage,
      });
 

    })
  },


  //下拉刷新
  onPullDownRefresh: function () {
    this.refreshData();
    wx.stopPullDownRefresh()
  },

  refreshData: function () {
    this.setData({
      pageNo: 1
    })
    this.getlist();
  },

  //触底时，加载更多
  onReachBottom: function () {
    if (this.data.hasNextPage) {
      this.setData({
        pageNo: this.data.pageNo + 1
      });
      this.getlist();
    }
  },
 

  toDetail:function(e){
    wx.navigateTo({
      url: '/pages/menber/settle/detail?id=' + e.currentTarget.dataset.id + '&sharedType=' + e.currentTarget.dataset.sharedtype,
    })
  }



})